<!--
 * @Description: 
 * @Author: Zhangx
 * @Date: 2023-08-02 16:10:37
 * @LastEditors: Zhangx
 * @LastEditTime: 2023-08-16 16:12:20
-->
<template>
   <el-row class="tac">
      <el-col>
        <el-menu
          active-text-color="#ffd04b"
          background-color="#207ffb"
          class="el-menu-vertical-demo"
          default-active="2"
          text-color="#fff"
          @open="handleOpen"
          @close="handleClose"
          :collapse="collapse"
        >
        <div class="pic">
          <img src="../assets/公式.png" alt="">
        </div>
        <h3>{{ collapse ? '封神' : '封神第一部·朝歌风云'}}</h3>
        <div class="center">
          <el-menu-item v-for="item in noChildren" :index="item.name" :key="item.name" @click="clickMenu(item)">
            <el-icon><House /></el-icon>
            <span>{{ item.label }}</span>
          </el-menu-item>
            <el-sub-menu v-for="item in hasChildren" :key="item.label" :index="item.label">
              <template #title>
                <el-icon><location /></el-icon>
                <span>{{ item.label }}</span>
              </template>
               <el-menu-item-group v-for="subItem in item.children" :key="subItem.name">
              <el-menu-item :index="subItem.name" @click="clickMenu(subItem)">{{ subItem.label }}</el-menu-item>
               </el-menu-item-group>
            </el-sub-menu>
        </div>
        </el-menu>
      </el-col>
    </el-row>
</template>

<script lang="ts" setup>
import router from '@/router'
import store from '../stores/index'
import { reactive, computed } from 'vue'
import {
  House,
  Location,
} from '@element-plus/icons-vue'
const state = reactive({
  ruleForm: [
    {
      path: '/',
      name: 'home',
      label: '首页',
      icon: 'House',
      url:'Home/Home'
    },
    {
      path: '/mall',
      name: 'mall',
      label: '商品管理',
      icon: 'Setting',
      url: 'prouduct/prouduct'
    },
    {
      path: '/user',
      name: 'user',
      label: '用户管理',
      icon: 'Document',
      url: 'UserManage/UserManage'
    },
    {
      label: '其他',
      icon: 'Document',
      children: [
        {
        path: '/pageone',
        name: 'pageone',
        label: '页面一',
        icon: 'Document',
        url: 'other/pageone'
        },
     {
          path: '/pagetwo',
          name: 'pagetwo',
          label: '页面2',
          icon: 'Document',
          url: 'other/pagetwo'
        },
  ]
  }
  ]
})
const noChildren = computed(() => {
   return state.ruleForm.filter(item => !item.children)
})
const hasChildren = computed(() => {
  return state.ruleForm.filter(item => item.children)
})
const collapse = computed(() => {
  return store.state.tab.isCollapse
})
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
// 点击菜单
const clickMenu = (item:any) => {
  // console.log(item)
  router.push(item.path)
  store.commit('selectMenu', item)
  console.log('111111111111')
}
</script>

<style lang="scss" scoped>
::v-deep(.el-menu) {
  height: 98vh; 
  // border-radius: 20px;
  box-sizing: border-box;
  margin-top: 10px;
  margin-left: 10px;
  margin-bottom: 10px;
  border-top-right-radius:50px;
  border-bottom-right-radius:50px;
  h3 {
    color: #fff;
    text-align: center;
  }
  .pic{
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin: 0 auto;
    box-sizing: border-box;
    padding-top: 20px;
    img {
      width: 100%;
      height: 100%;
    border-radius: 50%;
    }
  }
  .center {
    margin-top: 50px;
    box-sizing: border-box;
  }
}

</style>